package com.prs.crm.action.personalset;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.personalset.FastOpinion;
import com.prs.crm.service.personalSet.FastOpinionService;

public class FastOpinionAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private FastOpinion	fastOpinion;
	private FastOpinionService fastOpinionService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public FastOpinion getFastOpinion() {
		return fastOpinion;
	}
	public void setFastOpinion(FastOpinion fastOpinion) {
		this.fastOpinion = fastOpinion;
	}
	public FastOpinionService getFastOpinionService() {
		return fastOpinionService;
	}
	public void setFastOpinionService(FastOpinionService fastOpinionService) {
		this.fastOpinionService = fastOpinionService;
	}
	@Action("listFastOpinion")
	public String listFastOpinion(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(FastOpinion.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getFastOpinionService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editFastOpinion")
	public String editFastOpinion(){
		if(ids!=null){
			this.fastOpinion=this.getFastOpinionService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveFastOpinion", results={
			@Result(name="success",type="redirect",location="listFastOpinion"),
			@Result(name="error",type="chain",location="editFastOpinion")
	})
	public String saveFastOpinion(){
		fastOpinion.setType(0);
		this.getFastOpinionService().save(fastOpinion);
		return SUCCESS;
	}
	
	@Action(value="saveDefault", results={
			@Result(name="success",type="redirect",location="listFastOpinion"),
			@Result(name="error",type="chain",location="listFastOpinion")
	})
	public String saveDefault(){
		if(ids!=null){
			this.fastOpinion=this.getFastOpinionService().get(ids[0]);
		}
		fastOpinion.setType(1);
		this.getFastOpinionService().save(fastOpinion);
		return SUCCESS;
	}
	@Action(value="removeFastOpinion", results={
			@Result(name="success",type="redirect",location="listFastOpinion"),
			@Result(name="error",type="chain",location="listFastOpinion")
	})
	public String removeFastOpinion(){
		if(ids!=null){
			this.fastOpinion=this.getFastOpinionService().get(ids[0]);
		}
		this.getFastOpinionService().batchRemove(ids);
		return SUCCESS;
	}
}
